package com.zeta.eduservice.controller.Front;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.zeta.commonutils.R;
import com.zeta.eduservice.entity.question.EduQuestiongroup;
import com.zeta.eduservice.entity.vo.QuestionGroupVo;
import com.zeta.eduservice.entity.vo.front.folderListVo;
import com.zeta.eduservice.service.EduQuestiongroupService;

/**
 * <p>
 * 习题组 前端控制器
 * </p>
 *
 * @author zeta
 * @since 2020-08-24
 */
@CrossOrigin
@RestController
@RequestMapping("/eduservice/edu_questiongroup")
public class EduQuestiongroupController {
	
	@Autowired
	EduQuestiongroupService questionService;
	@PostMapping("")
	public R add(@RequestBody EduQuestiongroup questiongroup) {
		boolean save = questionService.save(questiongroup);
		if(save)
			return R.ok();
		else 
			return R.error();
	}
	@DeleteMapping("{id}")
	public R delete(@PathVariable String id) {
		boolean removeById = questionService.removeById(id);
		if(removeById)
			return R.ok();
		else 
			return R.error();
	}
	@PutMapping("")
	public R update(@RequestBody EduQuestiongroup questiongroup) {
		questionService.removeById(questiongroup);
		return R.ok();
	}
	@GetMapping("{folderId}")
	public R getfolderQuestionGroup(@PathVariable String folderId) {
		List<QuestionGroupVo> allQuestionByFolderId = questionService.getAllQuestionByFolderId(folderId);
		return R.ok().data("groupList",allQuestionByFolderId);
	}
	

}
